
const element = require('element-ui')
// 引入Vux
const common = {
    // 确认消息对话框
    confirm: (params) => {
        var p = params ? params : {},
            title = p.title ? p.title : "提示",
            message = p.message ? p.message : "此操作将永久删除该数据, 是否继续?";
        return element.MessageBox.confirm(message, title, {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: 'warning'
        });
    },
    // 通知消息 1
    notify: (params) => {
        var p = params ? params : {},
            title = p.title ? p.title : "提示",
            message = p.message ? p.message : "操作成功",
            type = p.type ? p.type : 'success';
        element.Notification({
            title: title,
            message: message,
            type: type,
            duration: 2000
        });
    },
    // 通知消息 2
    message: (params) => {
        var p = params ? params : {},
            title = p.title ? p.title : "提示",
            message = p.message ? p.message : "操作成功",
            type = p.type ? p.type : 'success',
            duration = p.duration ? p.duration : 3000;
        element.Message({
            title: title,
            message: message,
            type: type,
            duration: duration
        });
    },
    // 深对象Copy(不能Copy方法)
    copyObject(obj) {
        return JSON.parse(JSON.stringify(obj));
    },
    // 取数组对象中，对象的某一属性的值集合
    searchArrayObjectParams(data, params) {
        var arr = [];
        for (var i in data) {
            arr.push(data[i][params]);
        }
        return arr;
    },
    // 删除数组对象中指定的数组
    deleteArrayObjectActive(data, active) {
        var data = [...data];
        if (!active.length) return data;
        for (var i = data.length - 1; i >= 0; i--) {
            if (active.indexOf(data[i]) != -1) {
                data.splice(i, 1);
            }
        }
        return data;
    }
}

export default common